<template>
  <div class="wrapper">
    <div class="search">
      <div class="search__back" @click="handleBackClick">《</div>
      <div class="search__content">
        <span class="search__content__icon"></span>
        <input class="search__content__input" placeholder="请输入商品名称" />
      </div>
    </div>
    <shopInfo :item="item"  :hiddenBorder="true" v-show="item.imgUrl"/>
    <content />
    <Cart />
  </div>
</template>

<script>
import shopInfo from '@/components/ShopInfo.vue'
import { get } from '../../utils/request'
import { useRouter, useRoute } from 'vue-router'
import { reactive, toRefs } from 'vue'
import content from '@/views/shop/Content.vue'
import Cart from '@/views/shop/Cart.vue'
// 获取当前商铺信息
const useShopInfoEffect = () => {
  const route = useRoute() // 当前路径的信息
  const data = reactive({
    item: {}
  })
  const getItemData = async () => {
    const result = await get(`/api/shop/${route.params.id}`)
    if (result?.data?.errno === 0) {
      data.item = result.data.data
    }
  }
  const { item } = toRefs(data)
  return { getItemData, item }
}
// 点击回退逻辑
const useBackRouterEffect = () => {
  const router = useRouter()
  const handleBackClick = () => {
    router.back()
  }
  return handleBackClick
}
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'Shop',
  // eslint-disable-next-line vue/no-unused-components
  components: { shopInfo, content, Cart },
  setup () {
    const { item, getItemData } = useShopInfoEffect()
    const handleBackClick = useBackRouterEffect()
    getItemData()
    return { item, getItemData, handleBackClick }
  }
}
</script>

<style lang="scss" scoped>
.wrapper{
  padding: 0 .18rem;
}
.search{
  margin: .14rem 0 .04rem 0;
  display: flex;
line-height: .32rem;
  &__back{
    height: .32rem;
    width: .3rem;
    line-height: .32rem;
  }
  &__content{
    display: flex;
    flex: 1;
    background: #F5F5F5;
    border-radius: .16rem;
    &__icon{
      width: .44rem;
      text-align: center;
      color: #B7B7B7;
    }
    &__input{
      border: none;
      background: none;
      display: block;
      width: 100%;
      padding-right: .2rem;
      outline: none;
      border: none;
      color: #333;
      font-size: .14rem;
      &::placeholder{
        color: #333;
      }
    }
  }
}
</style>
